dojo.provide("miaigo.model.sgf.SGFGame");

dojo.require("miaigo.model.Game");

dojo.declare(
    "miaigo.model.sgf.SGFGame",
    [miaigo.model.Game],
    {
	// The Game tree (miaigo.model.sgf.SGFTree)
	_gameTree: null,

	constructor: function(createParam)
	{
	    if (createParam)
	    {
		this._gameTree = createParam.tree;
	    }
	},

	rootNode: function()
	{
	    return this._gameTree.getNode(0);
	},

	nextNode: function(refNode)
	{
	    var nextNodes = [];
	    if (!refNode || !refNode.getParent)
	    {
		return nextNodes;
	    }

	    var tree = refNode.getParent();
	    if (!tree)
	    {
		return nextNodes;
	    }

	    var refIndex = tree.indexOf(refNode);
	    if (refIndex < 0)
	    {
		return nextNodes;
	    }

	    var directNextNode = tree.getNode(refIndex + 1);
	    if (directNextNode)
	    {
		nextNodes.push(directNextNode);
	    }

	    if (refNode.getVariationCount() > 0)
	    {
		for (var varIndex=0; varIndex<refNode.getVariationCount(); varIndex++)
		{
		    var varTree = refNode.getVariation(varIndex);
		    var varNode = varTree.getNode(0);
		    if (varNode)
		    {
			nextNodes.push(varNode);
		    }
		}
	    }

	    return nextNodes;
	},

	// See miaigo.model.Game.buildGameInfo
	buildGameInfo: function()
	{
	    var root = this.rootNode();
	    if (root)
	    {
		return root._attrMap;
	    }

	    return null;
	}
    });